package com.xb.sourest.base;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xd.navi.NetWorkManager;
import com.xd.navi.OnNetStateChangeListener;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public abstract class BaseFragment extends Fragment implements OnNetStateChangeListener {

    protected Activity mActivity;


    protected  abstract  void initData();  //只处理传递过来的值，布局未加载出来
    protected abstract int initLayoutRes();  //布局


    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        if (context != null){
            mActivity = (Activity) context;
        }else {
            Log.d("Basefragment","context is Null");
        }

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        NetWorkManager.getInstance().addListener(this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(initLayoutRes(),container,false);
    }


    @Override
    public void onNetStateChange(boolean isConnect) {

    }
}
